/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.gr.jcash.dmp;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author gelson
 */
@Entity
@Table(name = "conta", catalog = "jcash", schema = "public")
@NamedQueries({
    @NamedQuery(name = "Conta.buscarTodos", query = "SELECT c FROM Conta c WHERE c.usuario = :p0 ORDER BY c.ctaDescricao"),
    @NamedQuery(name = "Conta.buscarPorId", query = "SELECT c FROM Conta c WHERE c.idCta = :p0 AND c.usuario = :p1"),
    @NamedQuery(name = "Conta.buscarPorDescricao", query = "SELECT c FROM Conta c WHERE c.ctaDescricao = :p0 AND c.usuario = :p1"),
    @NamedQuery(name = "Conta.buscarPorTipoCategoria", query = "SELECT c FROM Conta c WHERE c.categoria.catTipo in (:p0)  AND c.usuario = :p1"),
    @NamedQuery(name = "Conta.buscarPorCategoria", query = "SELECT c FROM Conta c WHERE c.categoria = :p0 AND c.usuario = :p1"),
    @NamedQuery(name = "Conta.countPorCategoria", query = "SELECT count(c.idCta) FROM Conta c WHERE c.categoria = :p0 AND c.usuario = :p1"),
    @NamedQuery(name = "Conta.count", query = "SELECT COUNT(c.idCta) FROM Conta c WHERE c.usuario = :p0")})
public class Conta extends EntidadeBase implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_cta", nullable = false)
    private Long idCta;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 100)
    @Column(name = "cta_descricao", nullable = false, length = 100)
    private String ctaDescricao;
    @JoinColumn(name = "id_usu", referencedColumnName = "id_usu", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Usuario usuario;
    @JoinColumn(name = "id_cat", referencedColumnName = "id_cat", nullable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Categoria categoria;
    @Basic(optional = true)
    @Column(name = "cta_data_inicial", nullable = true)
    @Temporal(TemporalType.DATE)
    private Date ctaDataInicial;
    @Basic(optional = true)
    @Column(name = "cta_saldo_inicial", nullable = true, precision = 2)
    private BigDecimal ctaSaldoInicial;

    public Conta() {
    }

    public Long getIdCta() {
        return idCta;
    }

    public void setIdCta(Long idCta) {
        this.idCta = idCta;
    }

    public String getCtaDescricao() {
        return ctaDescricao;
    }

    public void setCtaDescricao(String ctaDescricao) {
        this.ctaDescricao = ctaDescricao;
    }

    public Usuario getUsuario() {
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public Categoria getCategoria() {
        return categoria;
    }

    public void setCategoria(Categoria categoria) {
        this.categoria = categoria;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCta != null ? idCta.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Conta)) {
            return false;
        }
        Conta other = (Conta) object;
        if ((this.idCta == null && other.idCta != null) || (this.idCta != null && !this.idCta.equals(other.idCta))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return ctaDescricao;
    }
    
    @Override
    public void setId(Long id) {
        this.idCta = id;
}

    @Override
    public Long getId() {
        return idCta;
    }

    public Date getCtaDataInicial() {
        return ctaDataInicial;
    }

    public void setCtaDataInicial(Date ctaDataInicial) {
        this.ctaDataInicial = ctaDataInicial;
    }

    public BigDecimal getCtaSaldoInicial() {
        return ctaSaldoInicial;
    }

    public void setCtaSaldoInicial(BigDecimal ctaSaldoInicial) {
        this.ctaSaldoInicial = ctaSaldoInicial;
    }
}
